<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "device".
 *
 * @property int $id
 * @property int $parent_id 父节点id
 * @property string $name 名称
 * @property int $level 级别
 * @property int $status 状态
 * @property int $created_at 创建时间
 */
class Device extends Base
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'device';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['parent_id', 'level', 'status', 'created_at'], 'integer'],
            [['name'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'parent_id' => 'Parent ID',
            'name' => 'Name',
            'level' => 'Level',
            'status' => 'Status',
            'created_at' => 'Created At',
        ];
    }

    public function getParent(){
        return $this->hasOne(Device::class, ['id' => 'parent_id']);
    }
}
